#Copyright (C) Nial Peters 2013
#
#This file is part of pydoas.
#
#pydoas is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#pydoas is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with pydoas.  If not, see <http://www.gnu.org/licenses/>.
from doas import spec

class FitLimitsBase:
    pass


class Unlimited(FitLimitsBase):
    pass


class Fixed(FitLimitsBase):
    pass


class BoxLimits(FitLimitsBase):
    def __init__(self, low, high):
        self.low = low
        self.high = high


class LinkedLimits(FitLimitsBase):
    def __init__(self, linked_to):
        if not isinstance(linked_to, FitReference):
            raise TypeError("Invalid type \'%s\' for linked_to argument. " 
                            "Expecting a FitReference instance")
        self.linked_to = linked_to


class FitReference:
    def __init__(self, spectrum, initial_shift=0.0, limit_shift=Unlimited(), 
                 initial_squeeze=1.0, limit_squeeze=Unlimited()):
        
        #check args
        if not isinstance(spectrum, spec.Spectrum):
            raise TypeError("Invalid type \'%s\' for spectrum argument. " 
                            "Expecting a doas.spec.Spectrum instance")
        
        if not isinstance(limit_shift, FitLimitsBase):
            raise TypeError("Invalid type \'%s\' for limit_shift argument. " 
                            "Expecting a FitLimitsBase subclass instance e.g. "
                            "BoxLimits.")
        
        if not isinstance(limit_squeeze, FitLimitsBase):
            raise TypeError("Invalid type \'%s\' for limit_squeeze argument. " 
                            "Expecting a FitLimitsBase subclass instance e.g. "
                            "BoxLimits.")       
        
        
class FitScenario:
    def __init__(self, references, fitting_wavelengths, polynomial=3):
        #TODO - references must be iterable
        
        #TODO - polynomial must be an integer or None
        
        #TODO - check that the shift and squeeze limits are reasonable for the 
        #fitting wavelengths for all the references.
        pass
    
    
    def fit(self, spectrum):
        if not isinstance(spectrum, spec.Spectrum):
            raise TypeError("Invalid type \'%s\' for spectrum argument. " 
                            "Expecting a doas.spec.Spectrum instance")
        
        
            
